package LeetCode.leetcode860;

class Solution {
    public boolean lemonadeChange(int[] bills) {
        //1-->5
        //2-->10
        //3-->20
        int[] pocket = new int[] {0,0,0};
        for (int bill: bills) {
            switch (bill){
                case 5:
                    pocket[0]++;
                    break;
                case 10:
                    if (pocket[0] <= 0)
                        return false;
                    pocket[1]++;
                    pocket[0]--;
                    break;
                default:
                    if (pocket[1] > 0 && pocket[0] > 0){
                        pocket[2]++;
                        pocket[1]--;
                        pocket[0]--;
                    }else if (pocket[1] == 0 && pocket[0] >=3){
                        pocket[2]++;
                        pocket[0]-=3;
                    }else {
                        return false;
                    }
            }
        }
        return true;
    }
}